<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>检查单管理</title>
<link rel="stylesheet" href="${ctx}/resources/layui/css/layui.css">
</head>
<body style="padding: 10px;">
	<!-- 搜索条件开始 -->
	<form class="layui-form" method="post" id="searchFrm" lay-filter="searchFrm">
		<div class="layui-form-item">
		    <div class="layui-inline">
		      <label class="layui-form-label">检查单号</label>
		      <div class="layui-input-inline">
		        <input type="text" name="checkid" placeholder="请输入检查单号" autocomplete="off" class="layui-input">
		      </div>
		      <label class="layui-form-label">出租单号</label>
		      <div class="layui-input-inline">
		        <input type="text" name="rentid" placeholder="请输入出租单号" autocomplete="off" class="layui-input">
		      </div>
		      <label class="layui-form-label">存在问题</label>
		      <div class="layui-input-inline">
		        <input type="text" name="problem" placeholder="请输入存在问题" autocomplete="off" class="layui-input">
		      </div>
	      	</div>
     	</div>
     	<div class="layui-form-item">
	      	<div class="layui-inline">
	      		<label class="layui-form-label">检查描述</label>
		      <div class="layui-input-inline">
		        <input type="text" name="checkdesc" placeholder="请输入检查描述" autocomplete="off" class="layui-input">
		      </div>
		      <label class="layui-form-label">开始时间</label>
		      <div class="layui-input-inline">
		        <input type="text" id="startTime" name="startTime" readonly="readonly" class="layui-input" placeholder="请选择开始时间">
		      </div>
		      <label class="layui-form-label">结束时间</label>
		      <div class="layui-input-inline">
		        <input type="text" id="endTime" name="endTime" readonly="readonly" class="layui-input" placeholder="请选择结束时间">
		      </div>
		      	<button type="button" class="layui-btn layui-icon layui-icon-search"
					lay-submit="" lay-filter="doSearch">查询</button>
				<button type="reset" class="layui-btn layui-btn-warm layui-icon layui-icon-refresh">重置</button>
	      	</div>
      	</div>
	</form>
	<!-- 搜索条件结束-->
	
	<!-- 数据表格开始 -->
	<table class="layui-hide" id="checkTable" lay-filter="checkTable"></table>
	<!-- 数据表格结束 -->
	<!-- 表格行工具栏开始 -->
	<div style="display: none;" id="checkRowbar">
		<a class="layui-btn layui-btn-sm  layui-btn-warm" lay-event="update">修改</a>
	</div>
	<!-- 表格行工具栏结束 -->
	<!-- 添加和修改弹出层开始 -->
	<div style="display: none;padding: 10px;" id="addOrUpdateDiv">
		<form class="layui-form layui-row layui-col-space10" method="post" lay-filter="dataFrm"
			id="dataFrm">
			<div class="layui-form-item">
				<label class="layui-form-label">检查单号</label>
					<div class="layui-input-block">
						<input type="text" name="checkid" readonly="readonly"
							autocomplete="off" class="layui-input">
					</div>
			</div>
			
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">操作员</label>
					<div class="layui-input-inline">
						<input type="text" name="opername" readonly="readonly"
							autocomplete="off" class="layui-input">
					</div>
					<label class="layui-form-label">检查时间</label>
					<div class="layui-input-inline">
						<input type="text" name="checkdate" id="checkdate"
							required="required" placeholder="请选择检查时间" readonly="readonly"
							autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">存在问题</label>
					<div class="layui-input-inline">
						<input type="text" name="problem" lay-verify="required" placeholder="请输入存在问题"
							autocomplete="off" class="layui-input">
					</div>

					<label class="layui-form-label">赔付金额</label>
					<div class="layui-input-inline">
						<input type="number" name="paymoney" lay-verify="required|number"
							placeholder="请输入赔付金额" autocomplete="off" class="layui-input">
					</div>
				</div>
			</div>
				<div class="layui-form-item">
				
					<label class="layui-form-label">出租单号</label>
					<div class="layui-input-block">
						<input type="text" name="rentid" readonly="readonly"
							autocomplete="off" class="layui-input">
					</div>
				</div>
			<div class="layui-form-item">
				<div class="layui-block">
					<label class="layui-form-label">检查描述</label>
					<div class="layui-input-block">
						<textarea name="checkdesc" lay-verify="required" placeholder="请输入检查描述"
							autocomplete="off" class="layui-input layui-textarea"></textarea>
					</div>
				</div>
			</div>
			<div class="layui-form-item" style="text-align: center;">
				<div class="layui-inline">
					<button type="button" class="layui-btn layui-icon layui-icon-search"
						lay-submit="" lay-filter="doSubmit">保存</button>
				</div>
			</div>
		</form>
	</div>
	<!--   添加和修改弹出层结束 -->
	

<script src="${ctx}/resources/layui/layui.js"></script>
<script>
	var tableIns;
	layui.use(['layer','table','form','laydate'], function() {
		var $ = layui.$;
		var layer = layui.layer;
		var table = layui.table;
		var form = layui.form;
		var laydate = layui.laydate;
		//初始化开始时间
		laydate.render({
		  elem: '#startTime'
		  ,type: 'datetime'
		});
		//初始化结束时间
		laydate.render({
		  elem: '#endTime'
		  ,type: 'datetime'
		});
		//初始化检查日期
		laydate.render({
		  elem: '#checkdate'
		  ,type: 'datetime'
		});
		//初始化登录检查单数据表格
		tableIns = table.render({
			    elem: '#checkTable'					//渲染的目标对象
			    ,url:'${ctx}/check/checkList.action'	//数据接口
			    ,title: '检查单数据表'						//数据导出时的标题
			    ,height:"full-140"	
			    ,page: true			//是否启用分页
			    ,cols: [[			//列表数据
			      ,{field:'checkid', title:'检查单号',align:"center",width:"250"}
			      ,{field:'rentid', title:'出租单号', align:"center",width:"252"}
			      ,{field:'checkdate', title:'检查日期', align:"center",width:"160"}
			      ,{field:'problem', title:'存在问题', align:"center",width:"160"}
			      ,{field:'paymoney', title:'赔付金额', align:"center",width:"160"}
			      ,{field:'checkdesc', title:'检查描述', align:"center",width:"180"}
			      ,{field:'opername', title:'操作人', align:"center",width:"100"}
			      ,{field:'createtime', title:'创建时间', align:"center",width:"160"}
			      ,{fixed:'right', title:'操作', toolbar:"#checkRowbar", align:"center",width:"80"}
			    ]]
			  });
		//监听查询表单的提交
		form.on("submit(doSearch)",function(data){
			tableIns.reload({
				where: data.field
				,page: {
				  curr: 1 //重新从第 1 页开始
				}
			});		
		})
	 	//2. 监听行工具栏事件
		table.on('tool(checkTable)', function(obj){
		  var data = obj.data; //获得当前行数据
		  switch (obj.event) {
			case 'update':
				openUpdateCheck(data);
				break;
			}
		});
		var mainIndex;
		function openUpdateCheck(data){
			mainIndex = layer.open({
				type:1
				,title:"修改检查单"
				,content:$("#addOrUpdateDiv")
				,area:['700px']
				,success:function(ayero, index){
					//回显表单
					form.val('dataFrm',data);
					
				}
			});
		}
		//监听修改弹出层的提交操作
		form.on("submit(doSubmit)",function(data){
			//序列化表单数据
			var params = $("#dataFrm").serialize();
			$.post("${ctx}/check/updateCheck.action", params, function(result){
				if(result.success){
					//刷新数据表格
					tableIns.reload();
				}
				//显示响应提示信息
				layer.msg(result.message);
				//关闭弹出层
				layer.close(mainIndex);
			});
			//阻止表单提交
			return false;
		});
		
	});
</script>
</body>
</html>